//
//  YWReadInternalBaseClass1.m
//
//  Created by Yeewii@hotmail com on 16/6/15
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "YWReadInternalBaseClass1.h"
#import "YWReadAds.h"
#import "YWReadImgnewextra.h"


NSString *const kYWReadInternalBaseClass1Ptime = @"ptime";
NSString *const kYWReadInternalBaseClass1Digest = @"digest";
NSString *const kYWReadInternalBaseClass1Source = @"source";
NSString *const kYWReadInternalBaseClass1Title = @"title";
NSString *const kYWReadInternalBaseClass1ImgType = @"imgType";
NSString *const kYWReadInternalBaseClass1Img = @"img";
NSString *const kYWReadInternalBaseClass1PicCount = @"picCount";
NSString *const kYWReadInternalBaseClass1HasHead = @"hasHead";
NSString *const kYWReadInternalBaseClass1PhotosetID = @"photosetID";
NSString *const kYWReadInternalBaseClass1Lmodify = @"lmodify";
NSString *const kYWReadInternalBaseClass1SkipType = @"skipType";
NSString *const kYWReadInternalBaseClass1Template = @"template";
NSString *const kYWReadInternalBaseClass1Imgsrc = @"imgsrc";
NSString *const kYWReadInternalBaseClass1Prompt = @"prompt";
NSString *const kYWReadInternalBaseClass1Tag = @"tag";
NSString *const kYWReadInternalBaseClass1HasAD = @"hasAD";
NSString *const kYWReadInternalBaseClass1Docid = @"docid";
NSString *const kYWReadInternalBaseClass1Interest = @"interest";
NSString *const kYWReadInternalBaseClass1ReplyCount = @"replyCount";
NSString *const kYWReadInternalBaseClass1ClkNum = @"clkNum";
NSString *const kYWReadInternalBaseClass1UpTimes = @"upTimes";
NSString *const kYWReadInternalBaseClass1Id = @"id";
NSString *const kYWReadInternalBaseClass1Ads = @"ads";
NSString *const kYWReadInternalBaseClass1Subtitle = @"subtitle";
NSString *const kYWReadInternalBaseClass1Replyid = @"replyid";
NSString *const kYWReadInternalBaseClass1Program = @"program";
NSString *const kYWReadInternalBaseClass1RecType = @"recType";
NSString *const kYWReadInternalBaseClass1SpecialID = @"specialID";
NSString *const kYWReadInternalBaseClass1Imgnewextra = @"imgnewextra";
NSString *const kYWReadInternalBaseClass1SkipID = @"skipID";
NSString *const kYWReadInternalBaseClass1DownTimes = @"downTimes";
NSString *const kYWReadInternalBaseClass1unlikeReason = @"unlikeReason";



@interface YWReadInternalBaseClass1 ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation YWReadInternalBaseClass1

@synthesize ptime = _ptime;
@synthesize digest = _digest;
@synthesize source = _source;
@synthesize title = _title;
@synthesize imgType = _imgType;
@synthesize img = _img;
@synthesize picCount = _picCount;
@synthesize hasHead = _hasHead;
@synthesize photosetID = _photosetID;
@synthesize lmodify = _lmodify;
@synthesize skipType = _skipType;
@synthesize template = _template;
@synthesize imgsrc = _imgsrc;
@synthesize prompt = _prompt;
@synthesize tag = _tag;
@synthesize hasAD = _hasAD;
@synthesize docid = _docid;
@synthesize interest = _interest;
@synthesize replyCount = _replyCount;
@synthesize clkNum = _clkNum;
@synthesize upTimes = _upTimes;
@synthesize internalBaseClass1Identifier = _internalBaseClass1Identifier;
@synthesize ads = _ads;
@synthesize subtitle = _subtitle;
@synthesize replyid = _replyid;
@synthesize program = _program;
@synthesize recType = _recType;
@synthesize specialID = _specialID;
@synthesize imgnewextra = _imgnewextra;
@synthesize skipID = _skipID;
@synthesize downTimes = _downTimes;
@synthesize unlikeReason = _unlikeReason;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.ptime = [self objectOrNilForKey:kYWReadInternalBaseClass1Ptime fromDictionary:dict];
            self.digest = [self objectOrNilForKey:kYWReadInternalBaseClass1Digest fromDictionary:dict];
            self.source = [self objectOrNilForKey:kYWReadInternalBaseClass1Source fromDictionary:dict];
            self.title = [self objectOrNilForKey:kYWReadInternalBaseClass1Title fromDictionary:dict];
            self.imgType = [[self objectOrNilForKey:kYWReadInternalBaseClass1ImgType fromDictionary:dict] doubleValue];
            self.img = [self objectOrNilForKey:kYWReadInternalBaseClass1Img fromDictionary:dict];
            self.picCount = [[self objectOrNilForKey:kYWReadInternalBaseClass1PicCount fromDictionary:dict] doubleValue];
            self.hasHead = [[self objectOrNilForKey:kYWReadInternalBaseClass1HasHead fromDictionary:dict] doubleValue];
            self.photosetID = [self objectOrNilForKey:kYWReadInternalBaseClass1PhotosetID fromDictionary:dict];
            self.lmodify = [self objectOrNilForKey:kYWReadInternalBaseClass1Lmodify fromDictionary:dict];
            self.skipType = [self objectOrNilForKey:kYWReadInternalBaseClass1SkipType fromDictionary:dict];
            self.template = [self objectOrNilForKey:kYWReadInternalBaseClass1Template fromDictionary:dict];
            self.imgsrc = [self objectOrNilForKey:kYWReadInternalBaseClass1Imgsrc fromDictionary:dict];
            self.prompt = [self objectOrNilForKey:kYWReadInternalBaseClass1Prompt fromDictionary:dict];
            self.tag = [self objectOrNilForKey:kYWReadInternalBaseClass1Tag fromDictionary:dict];
            self.hasAD = [[self objectOrNilForKey:kYWReadInternalBaseClass1HasAD fromDictionary:dict] doubleValue];
            self.docid = [self objectOrNilForKey:kYWReadInternalBaseClass1Docid fromDictionary:dict];
            self.interest = [self objectOrNilForKey:kYWReadInternalBaseClass1Interest fromDictionary:dict];
            self.replyCount = [[self objectOrNilForKey:kYWReadInternalBaseClass1ReplyCount fromDictionary:dict] doubleValue];
            self.clkNum = [[self objectOrNilForKey:kYWReadInternalBaseClass1ClkNum fromDictionary:dict] doubleValue];
            self.upTimes = [[self objectOrNilForKey:kYWReadInternalBaseClass1UpTimes fromDictionary:dict] doubleValue];
            self.internalBaseClass1Identifier = [self objectOrNilForKey:kYWReadInternalBaseClass1Id fromDictionary:dict];
    NSObject *receivedYWReadAds = [dict objectForKey:kYWReadInternalBaseClass1Ads];
    NSMutableArray *parsedYWReadAds = [NSMutableArray array];
    if ([receivedYWReadAds isKindOfClass:[NSArray class]]) {
        for (NSDictionary *item in (NSArray *)receivedYWReadAds) {
            if ([item isKindOfClass:[NSDictionary class]]) {
                [parsedYWReadAds addObject:[YWReadAds modelObjectWithDictionary:item]];
            }
       }
    } else if ([receivedYWReadAds isKindOfClass:[NSDictionary class]]) {
       [parsedYWReadAds addObject:[YWReadAds modelObjectWithDictionary:(NSDictionary *)receivedYWReadAds]];
    }

    self.ads = [NSArray arrayWithArray:parsedYWReadAds];
            self.subtitle = [self objectOrNilForKey:kYWReadInternalBaseClass1Subtitle fromDictionary:dict];
            self.replyid = [self objectOrNilForKey:kYWReadInternalBaseClass1Replyid fromDictionary:dict];
            self.program = [self objectOrNilForKey:kYWReadInternalBaseClass1Program fromDictionary:dict];
            self.recType = [[self objectOrNilForKey:kYWReadInternalBaseClass1RecType fromDictionary:dict] doubleValue];
            self.specialID = [self objectOrNilForKey:kYWReadInternalBaseClass1SpecialID fromDictionary:dict];
    NSObject *receivedYWReadImgnewextra = [dict objectForKey:kYWReadInternalBaseClass1Imgnewextra];
    NSMutableArray *parsedYWReadImgnewextra = [NSMutableArray array];
    if ([receivedYWReadImgnewextra isKindOfClass:[NSArray class]]) {
        for (NSDictionary *item in (NSArray *)receivedYWReadImgnewextra) {
            if ([item isKindOfClass:[NSDictionary class]]) {
                [parsedYWReadImgnewextra addObject:[YWReadImgnewextra modelObjectWithDictionary:item]];
            }
       }
    } else if ([receivedYWReadImgnewextra isKindOfClass:[NSDictionary class]]) {
       [parsedYWReadImgnewextra addObject:[YWReadImgnewextra modelObjectWithDictionary:(NSDictionary *)receivedYWReadImgnewextra]];
    }

    self.imgnewextra = [NSArray arrayWithArray:parsedYWReadImgnewextra];
            self.skipID = [self objectOrNilForKey:kYWReadInternalBaseClass1SkipID fromDictionary:dict];
            self.downTimes = [[self objectOrNilForKey:kYWReadInternalBaseClass1DownTimes fromDictionary:dict] doubleValue];
        
      self.unlikeReason = [self objectOrNilForKey:kYWReadInternalBaseClass1unlikeReason fromDictionary:dict];
        
    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.ptime forKey:kYWReadInternalBaseClass1Ptime];
    [mutableDict setValue:self.digest forKey:kYWReadInternalBaseClass1Digest];
    [mutableDict setValue:self.source forKey:kYWReadInternalBaseClass1Source];
    [mutableDict setValue:self.title forKey:kYWReadInternalBaseClass1Title];
    [mutableDict setValue:[NSNumber numberWithDouble:self.imgType] forKey:kYWReadInternalBaseClass1ImgType];
    [mutableDict setValue:self.img forKey:kYWReadInternalBaseClass1Img];
    [mutableDict setValue:[NSNumber numberWithDouble:self.picCount] forKey:kYWReadInternalBaseClass1PicCount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.hasHead] forKey:kYWReadInternalBaseClass1HasHead];
    [mutableDict setValue:self.photosetID forKey:kYWReadInternalBaseClass1PhotosetID];
    [mutableDict setValue:self.lmodify forKey:kYWReadInternalBaseClass1Lmodify];
    [mutableDict setValue:self.skipType forKey:kYWReadInternalBaseClass1SkipType];
    [mutableDict setValue:self.template forKey:kYWReadInternalBaseClass1Template];
    [mutableDict setValue:self.imgsrc forKey:kYWReadInternalBaseClass1Imgsrc];
    [mutableDict setValue:self.prompt forKey:kYWReadInternalBaseClass1Prompt];
    [mutableDict setValue:self.tag forKey:kYWReadInternalBaseClass1Tag];
    [mutableDict setValue:[NSNumber numberWithDouble:self.hasAD] forKey:kYWReadInternalBaseClass1HasAD];
    [mutableDict setValue:self.docid forKey:kYWReadInternalBaseClass1Docid];
    [mutableDict setValue:self.interest forKey:kYWReadInternalBaseClass1Interest];
    [mutableDict setValue:[NSNumber numberWithDouble:self.replyCount] forKey:kYWReadInternalBaseClass1ReplyCount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.clkNum] forKey:kYWReadInternalBaseClass1ClkNum];
    [mutableDict setValue:[NSNumber numberWithDouble:self.upTimes] forKey:kYWReadInternalBaseClass1UpTimes];
    [mutableDict setValue:self.internalBaseClass1Identifier forKey:kYWReadInternalBaseClass1Id];
    NSMutableArray *tempArrayForAds = [NSMutableArray array];
    for (NSObject *subArrayObject in self.ads) {
        if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForAds addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForAds addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForAds] forKey:kYWReadInternalBaseClass1Ads];
    [mutableDict setValue:self.subtitle forKey:kYWReadInternalBaseClass1Subtitle];
    [mutableDict setValue:self.replyid forKey:kYWReadInternalBaseClass1Replyid];
    [mutableDict setValue:self.program forKey:kYWReadInternalBaseClass1Program];
    [mutableDict setValue:[NSNumber numberWithDouble:self.recType] forKey:kYWReadInternalBaseClass1RecType];
    [mutableDict setValue:self.specialID forKey:kYWReadInternalBaseClass1SpecialID];
    NSMutableArray *tempArrayForImgnewextra = [NSMutableArray array];
    for (NSObject *subArrayObject in self.imgnewextra) {
        if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForImgnewextra addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForImgnewextra addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForImgnewextra] forKey:kYWReadInternalBaseClass1Imgnewextra];
    [mutableDict setValue:self.skipID forKey:kYWReadInternalBaseClass1SkipID];
    [mutableDict setValue:[NSNumber numberWithDouble:self.downTimes] forKey:kYWReadInternalBaseClass1DownTimes];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.ptime = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Ptime];
    self.digest = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Digest];
    self.source = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Source];
    self.title = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Title];
    self.imgType = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1ImgType];
    self.img = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Img];
    self.picCount = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1PicCount];
    self.hasHead = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1HasHead];
    self.photosetID = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1PhotosetID];
    self.lmodify = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Lmodify];
    self.skipType = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1SkipType];
    self.template = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Template];
    self.imgsrc = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Imgsrc];
    self.prompt = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Prompt];
    self.tag = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Tag];
    self.hasAD = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1HasAD];
    self.docid = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Docid];
    self.interest = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Interest];
    self.replyCount = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1ReplyCount];
    self.clkNum = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1ClkNum];
    self.upTimes = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1UpTimes];
    self.internalBaseClass1Identifier = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Id];
    self.ads = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Ads];
    self.subtitle = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Subtitle];
    self.replyid = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Replyid];
    self.program = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Program];
    self.recType = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1RecType];
    self.specialID = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1SpecialID];
    self.imgnewextra = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1Imgnewextra];
    self.skipID = [aDecoder decodeObjectForKey:kYWReadInternalBaseClass1SkipID];
    self.downTimes = [aDecoder decodeDoubleForKey:kYWReadInternalBaseClass1DownTimes];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_ptime forKey:kYWReadInternalBaseClass1Ptime];
    [aCoder encodeObject:_digest forKey:kYWReadInternalBaseClass1Digest];
    [aCoder encodeObject:_source forKey:kYWReadInternalBaseClass1Source];
    [aCoder encodeObject:_title forKey:kYWReadInternalBaseClass1Title];
    [aCoder encodeDouble:_imgType forKey:kYWReadInternalBaseClass1ImgType];
    [aCoder encodeObject:_img forKey:kYWReadInternalBaseClass1Img];
    [aCoder encodeDouble:_picCount forKey:kYWReadInternalBaseClass1PicCount];
    [aCoder encodeDouble:_hasHead forKey:kYWReadInternalBaseClass1HasHead];
    [aCoder encodeObject:_photosetID forKey:kYWReadInternalBaseClass1PhotosetID];
    [aCoder encodeObject:_lmodify forKey:kYWReadInternalBaseClass1Lmodify];
    [aCoder encodeObject:_skipType forKey:kYWReadInternalBaseClass1SkipType];
    [aCoder encodeObject:_template forKey:kYWReadInternalBaseClass1Template];
    [aCoder encodeObject:_imgsrc forKey:kYWReadInternalBaseClass1Imgsrc];
    [aCoder encodeObject:_prompt forKey:kYWReadInternalBaseClass1Prompt];
    [aCoder encodeObject:_tag forKey:kYWReadInternalBaseClass1Tag];
    [aCoder encodeDouble:_hasAD forKey:kYWReadInternalBaseClass1HasAD];
    [aCoder encodeObject:_docid forKey:kYWReadInternalBaseClass1Docid];
    [aCoder encodeObject:_interest forKey:kYWReadInternalBaseClass1Interest];
    [aCoder encodeDouble:_replyCount forKey:kYWReadInternalBaseClass1ReplyCount];
    [aCoder encodeDouble:_clkNum forKey:kYWReadInternalBaseClass1ClkNum];
    [aCoder encodeDouble:_upTimes forKey:kYWReadInternalBaseClass1UpTimes];
    [aCoder encodeObject:_internalBaseClass1Identifier forKey:kYWReadInternalBaseClass1Id];
    [aCoder encodeObject:_ads forKey:kYWReadInternalBaseClass1Ads];
    [aCoder encodeObject:_subtitle forKey:kYWReadInternalBaseClass1Subtitle];
    [aCoder encodeObject:_replyid forKey:kYWReadInternalBaseClass1Replyid];
    [aCoder encodeObject:_program forKey:kYWReadInternalBaseClass1Program];
    [aCoder encodeDouble:_recType forKey:kYWReadInternalBaseClass1RecType];
    [aCoder encodeObject:_specialID forKey:kYWReadInternalBaseClass1SpecialID];
    [aCoder encodeObject:_imgnewextra forKey:kYWReadInternalBaseClass1Imgnewextra];
    [aCoder encodeObject:_skipID forKey:kYWReadInternalBaseClass1SkipID];
    [aCoder encodeDouble:_downTimes forKey:kYWReadInternalBaseClass1DownTimes];
}

- (id)copyWithZone:(NSZone *)zone
{
    YWReadInternalBaseClass1 *copy = [[YWReadInternalBaseClass1 alloc] init];
    
    if (copy) {

        copy.ptime = [self.ptime copyWithZone:zone];
        copy.digest = [self.digest copyWithZone:zone];
        copy.source = [self.source copyWithZone:zone];
        copy.title = [self.title copyWithZone:zone];
        copy.imgType = self.imgType;
        copy.img = [self.img copyWithZone:zone];
        copy.picCount = self.picCount;
        copy.hasHead = self.hasHead;
        copy.photosetID = [self.photosetID copyWithZone:zone];
        copy.lmodify = [self.lmodify copyWithZone:zone];
        copy.skipType = [self.skipType copyWithZone:zone];
        copy.template = [self.template copyWithZone:zone];
        copy.imgsrc = [self.imgsrc copyWithZone:zone];
        copy.prompt = [self.prompt copyWithZone:zone];
        copy.tag = [self.tag copyWithZone:zone];
        copy.hasAD = self.hasAD;
        copy.docid = [self.docid copyWithZone:zone];
        copy.interest = [self.interest copyWithZone:zone];
        copy.replyCount = self.replyCount;
        copy.clkNum = self.clkNum;
        copy.upTimes = self.upTimes;
        copy.internalBaseClass1Identifier = [self.internalBaseClass1Identifier copyWithZone:zone];
        copy.ads = [self.ads copyWithZone:zone];
        copy.subtitle = [self.subtitle copyWithZone:zone];
        copy.replyid = [self.replyid copyWithZone:zone];
        copy.program = [self.program copyWithZone:zone];
        copy.recType = self.recType;
        copy.specialID = [self.specialID copyWithZone:zone];
        copy.imgnewextra = [self.imgnewextra copyWithZone:zone];
        copy.skipID = [self.skipID copyWithZone:zone];
        copy.downTimes = self.downTimes;
    }
    
    return copy;
}


@end
